<%-- 
    Document   : NewMessage
    Created on : Dec 6, 2011, 11:14:51 PM
    Author     : hendrikde
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Compose New Message</title>
    </head>
    <body>
        <h1>Compose New Message</h1>
        <%
        String recipient;
        String subject;
        try {
            recipient = request.getParameter("PERS");
            subject = request.getParameter("SUBJ");
}
        catch (Exception e) {
            recipient = new String();
            subject = new String();
}
%>         
<form name ="NewMessage" action="SendMessage.jsp" method="Post">
    <%
    
    DBClasses.GetConnection gc = new DBClasses.GetConnection();
    java.sql.Connection conn = gc.getConnection();
    
    try {
        java.sql.ResultSet rs = conn.createStatement().executeQuery("SELECT CustomerID, Concat(FirstName, ' ', LastName) AS Name FROM customer "
                + "ORDER BY Concat(Firstname, LastName)");
    %>
    To: <select name="recipient">
        <%
        while (rs.next()) {

            if (rs.getString(1).equals(recipient)) {%>
            <option value="<%=rs.getString(1)%>" selected="selected"><%=rs.getString(2)%></option>
            <%;
            }
            else { %>
            <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>
            <%;}
        }
               }
    catch (Exception e) {
        e.printStackTrace();
    }
        %>
    </select>
    Subject: <input type="text" name="subject" value="<%=subject%>"/></br>
    <textarea rows="15" cols="30" name="content">Enter Message...</textarea><br />
    Send: <input type="submit" value="Send Message"/>
</form>
    <input type="button" name="return" value="Return" onclick="window.location='MessageIndex.jsp'"/>
    </body>
</html>
